<!DOCTYPE html>
<html>
	<head>
		<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1">
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="../../css/iuapmobile.um.css">
		<link rel="stylesheet" href="../../css/font-icons.css">
		<link rel="stylesheet" type="text/css" href="../../css/iuapmobile.um.listview.css">
		<link rel="stylesheet" href="../../css/iscroll.css" />
		<script src="../../js/summer.js" ></script>
		<script src="../../js/jquery.min.js" ></script>
		<script src="../../js/iscroll.js"></script>
		<script src="../../js/Frameworks/iuapmobile.frameworks.ui.js" ></script>
		<script type="text/javascript" src="../../js/knockout.js"></script>
		<script type="text/javascript" src="../../js/Frameworks/iuapmobile.frameworks.listview.js"></script>
		<style>
			#select1_dummy, #select2_dummy, #select3_dummy {
				border: none;
				padding-left: 10px;
				color: #555;
				font-size: 17px;
				text-align: right;
				margin-right: 20px;
				width: 100%;
			}
			#select1_dummy:disabled, #select2_dummy:disabled, #select3_dummy:disabled {
				background: #fff;
			}

		</style>

		<style>
			.msg-info {
				position: relative;
			}
			.msg-info .um-badge {
				position: absolute;
				right: -10px;
				font-size: 12px;
			}
			.msg-header {
				width: 40px;
				height: 40px;
				line-height: 40px;
				background: blue;
				border-radius: 50%;
				text-align: center;
				color: white;
			}
			.t_area {
				width: 300px;
				overflow-y: visible
			}
		</style>
	</head>
	<body class="f14">
		<div class="um-win" id="disassemble_in">
			<div class="um-header" >
				<h3>拆机实收</h3>
				<a href="#" class="um-back back">返回</a>
				<a class="um-header-right" onclick="submitdata();">提交</a>
			</div>

			<div class="um-content" ng-app="myApp" ng-controller="myCtrl">
				<ul class="um-list">
					<li class="um-list-item">
						<div class="um-list-item-inner">
							<span class="h pa um-box-vc um-red f20 pl5" >*</span>
							<div class="um-list-item-left pl15">
								仓库:
							</div>
							<div class="um-list-item-right">
								<select id='select2' class="select" ng-model="ij">
									<option ng-repeat="r in cangku">{{r.doc_name}}</option>
								</select>
							</div>
						</div>
					</li>
					<li class="um-list-item">
						<div class="um-list-item-inner">
							<div class="um-list-item-right">
								<div class="um-box">
									<div class="um-bf4 p5">
										<input id="findvalue" ng-model="esn" type="text"  class="form-control tr" oninput="fun()"  placeholder="请填写">
									</div>
									<div class="um-bf1 p5">
										<img  id="esn" onclick='scannerCode("esn")' ng-src="../../img/myimg/scanner.png" class="h50 "/>
									</div>
								</div>
							</div>
						</div>
					</li>
				</ul>

				<div class="um-listview-wrap" id="listview" >
					<ul class="um-list um-no-active" data-bind="foreach: data">
						<li class="um-listview-row" >

							<a href="#" class="um-list-item um-swipe-action um-no-icon">
							<div class="um-list-item-inner">
								<div class="um-list-item-body um-text-overflow f14" style="padding-right:5px;">

									<div class="um-bgc-blue um-white pt5 pb5 ">
										<input type="checkbox" name="che" disabled="true"  data-bind="attr: {id: sbbh01}">
										︱点位编号:<span data-bind="text:dwh01"></span>
									</div>
									<div class="w">
										<div class="um-md-6 w_50 fl mt5 mb5">
											设备编号:<span data-bind="text:sbbh01"></span>
										</div>
										<div class="um-md-6 w_50 fl mt5 mb5">
											设备型号:<span data-bind="text:sbxh01"></span>
										</div>
									</div>
									<div class="w">
										<div class="um-md-6 w_50 fl mt5 mb5">
											商家经营名称:<span data-bind="text:sjjymc01"></span>
										</div>
										<div class="um-md-6 w_50 fl mt5 mb5">
											商家经营地址:<span data-bind="text:sjjydz01"></span>
										</div>
									</div>
									<div class="w">
										<div class="um-md-6 w_50 fl mt5 mb5">
											资产编号:<span data-bind="text:zcbh01"></span>
										</div>
										<div class="um-md-6 w_50 fl mt5 mb5">
											拆机原因:<span data-bind="text:cjyy01"></span>
										</div>
									</div>
									<div class="w">
										<div class="um-md-6 w_50 fl mt5 mb5">
											情况说明: 											<textarea data-bind="text:qksm01" readonly="readonly"  class="form-control t_area"></textarea>
										</div>
										<div class=" fl mt5 mb5">
											品牌:<span data-bind="text:pp01"></span>
										</div>
									</div>
								</div>
							</div> </a>
						</li>
					</ul>
				</div>

			</div>

			<!--<div class="um-footer">

			</div>-->
		</div>
		<script src="../../js/angular.min.js"></script>

		<script>
			var updateList;
			var billid;
			var Pageparams;
			var anscope;
			var datas = new Array();
			var persions = new Array();
			var selectarr = new Array();
			var submitdatas = new Array();
			var copyArr;
			var selectdatas;
			var cleanArr;
			var cleanOpen;
			var Resultsort;
			var cwarehouseid;
			$(function() {
				// var curr = new Date().getFullYear();
				var opt = {
					'date' : {
						preset : 'date'
					},
					'select' : {
						preset : 'select'
					}
				};
				$('.select').scroller('destroy').scroller($.extend(opt['select'], {
					theme : "ios7",
					mode : "scroller",
					display : "bottom",
					animate : ""
				}));
			});

			function scannerCode(id) {
				summer.openScanner({
					callback : function(args) {
						anscope[id] = summer.getDeviceInfo().os == "ios" ? args : args.umdcode;
						//$("#" + id).css("display", "none");
						Resultsort(anscope[id]);
						anscope.$apply();
					}
				});
			}

			function fun() {
				Resultsort($("#findvalue").val());
			}

			function bindCk() {

				doPost(adressHead.ISjtzImpl, "getBdDoc", {
					dataParm : {
						dostype : "nc_ck_" + summer.getStorage("userinfo").empId
					}
				}, function(jsons) {
					console.log( typeof jsons);
					anscope.cangku = jsons;
					anscope.$apply();
					$("#select2_dummy").val("请选择");
				}, null, true);
			}

			$(function() {
				var installListindex = 1;
				var installList = [];
				var isChecked;
				var ViewModel = function() {
				};
				var viewModel = new ViewModel();
				//构造控件实例
				var listview = UM.listview("#listview");
				//当前第几页
				viewModel.data = ko.observableArray([]);
				ko.applyBindings(viewModel);
				//绑定叶号，是否第一次bool
				updateList = function(index, cout) {
					doPost(adressHead.IDisassembleImpl, "appCjpgCheckList", {
						dataParm : {
							empId : summer.getStorage("userinfo").psnid, //,
							//billid : billid,
							//status : 1
							star : index,
							count : cout
						}
					}, function(data) {
						if (data.result == 1) {
							console.log(data);
							if (data.data.length != "") {
								for (var i = 0; i < data.data.length; i++) {
									console.log(data.data[i]);
									var msgtype = parseInt(data.data[i].type) - 1;
									viewModel.data.push({
										'ids' : "id" + i,
										'dwh01' : data.data[i].dwh01,
										'sbbh01' : data.data[i].sbbh01,
										'sbxh01' : data.data[i].sbxh01,
										'sjjymc01' : data.data[i].sjjymc01,
										'sjjydz01' : data.data[i].sjjydz01,
										'zcbh01' : data.data[i].zcbh01,
										'cjyy01' : data.data[i].cjyy01,
										'qksm01' : data.data[i].qksm01,
										'pp01' : data.data[i].pp01,
										'bodyid' : data.data[i].bodyid,
										'check' : false
									});

								};
								installListindex += data.data.length;
								var list = document.getElementsByName("che");
								//对表单中所有的input进行遍历
								for (var i = 0; i < list.length; i++) {
									//判断是否为文本框
									list[i].addEventListener("click", function(e) {
										console.log(this);
										e.stopPropagation();
									})
								}
								datas = viewModel.data().slice(0);
							} else {
								UM.toast({
									title : '友情提示：',
									text : '没有更多单据',
									duration : 1000
								});
							}
						} else {
							UM.toast({
								title : '友情提示：',
								text : data.msg,
								duration : 1000
							});
						}
						listview.refresh();
					}, function(err) {
						console.log(err);
					});

					/**
					 * 反选处理
					 */
					cleanOpen = function() {
						var list = document.getElementsByName("che");
						//对表单中所有的input进行遍历
						for (var i = 0; i < list.length; i++) {
							//判断是否为文本框
							list[i].addEventListener("click", function(e) {
								if (!(this.checked)) {
									console.log("new arr" + JSON.stringify(datas));
									datas[i - 1].check = false;
									this.disabled = "true"
								}
								e.stopPropagation();
							})
						};
					};
					cleanOpen();
					$("textarea").each(function(i) {
						$("textarea").eq(i).css("width", ($(".w").eq(0).get(0).offsetWidth) - 25 + "px");
					})
					/**
					 *  排序，选中处理
					 */
					Resultsort = function(data) {
						for (var k = 0; k < datas.length; k++) {
							if (datas[k].zcbh01 == data) {
								datas.unshift(datas[k]);
								datas.splice(k + 1, 1);
								try {
									while (viewModel.data.shift()) {
									}
									listview.refresh();
								} catch(e) {
								};
								for (var i = 0; i < datas.length; i++) {
									viewModel.data.push(datas[i]);
									if (datas[i].zcbh01 == data) {
										datas[i].check = true;
										$("#" + datas[i].sbbh01).removeAttr('disabled');
										$("#" + datas[i].sbbh01).prop("checked", "true");
									}
									if (datas[i].check == true) {
										$("#" + datas[i].sbbh01).removeAttr('disabled');
										$("#" + datas[i].sbbh01).prop("checked", "true");
									}
									listview.refresh();
									cleanOpen();
								}
							}

						}
					}
					return datas;
				};
				updateList(1, 4);
				window.bind = function() {
					updateList(1, 4);
				};
				//添加控件方法
				/*listview.on("pullDown", function(sender) {
					selectarr = [];
					$('input:checkbox[name=che]:checked').each(function(i) {
						selectarr.push(datas[i]);
					});
					console.log(selectarr);
					selectarr = [];
					$('input:checkbox[name=che]:checked').each(function(i) {
						selectarr.push(datas[i]);
					});
					console.log(selectarr);
					try {
						while (viewModel.data.shift()) {
						}
						listview.refresh();
					} catch(e) {
					}

					//viewModel.data.unshift(row);
					sender.refresh();
				});*/
				listview.on("pullUp", function(sender) {
					updateList(installListindex, 4);
					console.log(datas);
					sender.refresh();
				});
				listview.on("itemClick", function(sender, args) {
					var docnum = viewModel.data()[args.rowIndex].sbbh1;
					if ($("#" + docnum).is(':checked')) {
						$("#" + docnum).prop("checked", false);
					}
					sender.refresh();
					//toasts(args.rowIndex);
					//这里可以处理行点击事件，参数sender即为当前列表实例对象，args对象有2个属性，即rowIndex(行索引)和$target(目标行的jquery对象)
					//toasts("您点击了列表的第" + (args.rowIndex + 1) +　"行！");
				});

				cleanArr = function() {
					try {
						while (viewModel.data.shift()) {
						}
					} catch(e) {
					}
				}
			});

			function rebind() {
				window.bind();
			}

			//提交数据

			function submitdata() {
				if (!cwarehouseid) {
					alert("请选择仓库");
					return;
				}

				submitdatas = [];
				$('input:checkbox[name=che]:checked').each(function(i) {
					submitdatas.push({
						empId : summer.getStorage('userinfo').empId,
						bodyid : datas[i].bodyid,
						zcbh01 : datas[i].zcbh01,
						pp01 : datas[i].pp01,
						cwarehouseid : cwarehouseid,
						sbxh01 : datas[i].sbxh01
					})
				});
				if (submitdatas != "") {
					doPost(adressHead.IDisassembleImpl, "saveSbrkd_old", {
						dataParm : submitdatas[0]
					}, function(data) {
						if (data.result == 1) {
							UM.toast({
								title : '友情提示：',
								text : data.msg,
								duration : 1000
							});
							cleanArr();
							updateList(1, 4);
						} else {
							UM.toast({
								title : '友情提示：',
								text : data.msg,
								duration : 1000
							});
						}
					}, function(err) {
						console.log(err);
					});
				} else {
					UM.toast({
						title : '友情提示：',
						text : '未选择提交数据',
						duration : 1000
					});
				}
			}


			$('.select').change(function() {
				$("#" + $(this).attr("id") + "_dummy").val($(this).find("option:selected").text());
				cwarehouseid = getpk($("#" + $(this).attr("id") + "_dummy").val());
			});

			function getpk(pkname) {
				for (var i = 0; i < anscope.cangku.length; i++) {
					if (anscope.cangku[i].doc_name == pkname) {
						return anscope.cangku[i].pk_doc;
					}
				}
			}

			function isRepeat(arr) {
				var flag = false;
				for (var i = 1; i < arr.length; i++) {
					if (arr[0] != arr[i]) {
						flag = true;
					}
				}
				return flag;

			}

			/**
			 *angular 控件初始化
			 */
			var app = angular.module('myApp', []);
			app.controller('myCtrl', function($scope, $http) {
				anscope = $scope;
				anscope.persion = ["张三", "李四"];
				//jsons;
				anscope.installer = ["张三", "李四"];
				//jsons;
			});
			summerready = function() {
				if (summer.pageParam) {
					billid = summer.pageParam.billid;
					updateList(1, 4);
				}
				setTimeout(function() {
					bindCk();
				}, 300)
			}
		</script>

	</body>
</html>
<script type="text/javascript" src="../../js/Myjs/Common.js"></script>